

class Stack(object):
    def __init__(self):
        self.stack=[]
    def pop(self):
        if self.stack:
            return self.stack.pop()
        else:
            return None
        
    def push(self,obj):
        self.stack.append(obj)
        
    def peek(self):
        if self.stack:
            return self.stack[-1]
        else:
            return None
    def length(self):
        return len(self.stack)
sign_list=['+','-','*','/',]
sign_weight={'+':1,
             '-':1,
             '*':2,
             '/':2}
def _calculate(num_stack):
    num_stack.stack.reverse()
    print 'reverse',num_stack.stack
    tnum_s=Stack()
    while num_stack.stack:
        c=num_stack.pop()
        if c in sign_list:
            sub_formula=[]
            sub_formula.insert(2,tnum_s.pop())
            sub_formula.insert(0,tnum_s.pop())
            sub_formula.insert(1,c)
            sub_f=''.join(sub_formula)
            print sub_f
            r=eval(sub_f)
            print r
            tnum_s.push(str(r))
        else:
            tnum_s.push(c)
    result=tnum_s.pop()
    return result

def calculate(formula):
    '''2*10+5*6'''
    result=0
    sign_stack=Stack()
    num_stack=Stack()
    sign_list=['+','-','*','/',]
    sign_weight={'+':1,
                 '-':1,
                 '*':2,
                 '/':2}
    i=0
    while i<len(formula):
        print formula[i]
        if formula[i] in sign_list:
            while sign_stack.length() and sign_weight[formula[i]]<=sign_weight[sign_stack.peek()]:
                num_stack.push(sign_stack.pop())
            sign_stack.push(formula[i])
            i+=1
        else:
            sub_num=''
            while formula[i] not in sign_list:
                sub_num+=formula[i]
                i+=1
                if i>=len(formula):
                    break;
            num_stack.push(sub_num)
    while sign_stack.stack:
        num_stack.push(sign_stack.pop())
    #print sign_stack.stack
    print num_stack.stack
    print _calculate(num_stack),
calculate('26*10+5*100+56/9+5')






